/*
 * Copyright (c) 2011 Jean-Marc Perronne
 * Ensisa, 12 rue des Freres Lumieres, F-68093 Mulhouse cedex
 * All rights reserved.
 *
 * The copyright of this software is owned by Werner Randelshofer. 
 * You may not use, copy or modify this software, except in  
 * accordance with the license agreement you entered into with  
 * Jean-Marc Perronne. For details see accompanying license terms. 
 */

package fr.uha.ensisa.jmp.drone.vision;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

import fr.uha.ensisa.jmp.drone.navdata.options.VisionDetect;
import fr.uha.ensisa.jmp.drone.ui.cockpit.VideoPanelDraft;


public class TagsDraft implements VideoPanelDraft
{
	private final static Color RECT_COLOR = Color.CYAN;
	private final static int TAGS_SCREEN_REF_SIZE = 1000;

	public VisionDetect tags;

	public TagsDraft()
	{
		this.tags = null;
	}

	public synchronized void setData(VisionDetect tags)
	{
		this.tags = tags;
	}

	@Override
	public synchronized void draw(Graphics2D g2d, BufferedImage videoImage)
	{
		g2d = (Graphics2D)videoImage.getGraphics();
		g2d.setColor(RECT_COLOR);

		final float ch = ((float) videoImage.getWidth()) / TAGS_SCREEN_REF_SIZE;
		final float cv = ((float) videoImage.getHeight()) / TAGS_SCREEN_REF_SIZE;

		//g2d.drawRect((int) (460*ch), (int) (460*cv), (int) (80 * ch), (int) (80 * cv));

		if (this.tags == null) return;

		//System.out.println(tags);

		for (int i = 0; i < tags.xc.length; i++)
		{
			g2d.drawRect((int) ((this.tags.xc[i] - this.tags.width[i]/2) * ch), (int) ((this.tags.yc[i] - this.tags.height[i]/2) * cv), (int) (this.tags.width[i] * ch), (int) (this.tags.height[i] * cv));
		}
		this.tags = null;
	}

}
